
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as DE
from selenium.webdriver.support.ui import WebDriverWait
# option = webdriver.EdgeOptions()  # todo：chrome浏览器配置项
# option.add_experimental_option("detach", True)
# driver = webdriver.Edge(options=option)
option = webdriver.EdgeOptions()  # todo：chrome浏览器配置项
option.add_experimental_option("detach", True)


class Search_bonescience:
    def __init__(self,driver):
        self.driver = driver
        # self.option = webdriver.EdgeOptions()  # todo：chrome浏览器配置项
        # self.option.add_experimental_option("detach", True)
        # self.driver = webdriver.Edge(options=self.option)

        self.driver.get("http://www.bjhospital.net/")
        self.driver.maximize_window()
        driver.implicitly_wait(11)
    def input_zjhospital(self,text:str):
        WebDriverWait(self.driver,10,0.5).until(DE.presence_of_element_located((By.CLASS_NAME,"keyword"))).send_keys(text)
    def button(self):
        WebDriverWait(self.driver,10,0.5).until(DE.presence_of_element_located((By.CLASS_NAME,"btn"))).click()
    def first_title(self):
        WebDriverWait(self.driver,10,0.5).until(DE.presence_of_element_located((By.XPATH,"/html/body/div[4]/ul/li[1]/div[1]/h5/a"))).click()
    def assert_result(self):
        win = self.driver.window_handles
        self.driver.switch_to.window(win[-1])
        assert_result1 =WebDriverWait(self.driver,10,0.5) .until(DE.presence_of_element_located((By.XPATH,"/html/body/div[3]/div/div/article/h1"))).text
        print(assert_result1)
        assert assert_result1 =="毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
    def quit(self):
        self.driver.quit()
if __name__ =='__main__':
    driver = webdriver.Edge(options=option)
    shuai = Search_bonescience(driver)
    shuai.input_zjhospital("骨科")
    shuai.button()
    shuai.first_title()
    shuai.assert_result()
    print(driver.title)
    shuai.quit()
    print(driver.title)
